/*
 * Copyright (C) 2009 M. Hautle.
 * 
 * This file is part of TrackedBean.
 * 
 * TrackedBean is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * TrackedBean is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with TrackedBean. If not, see <http://www.gnu.org/licenses/>.
 */
package ch.trackedbean.tracking;

import java.beans.*;

/**
 * Interface describing a status of a bean and it's properties.
 * 
 * @param <T> The owner type
 * @author M. Hautle
 */
public interface IBeanStatus<T> {
    /** Property for the status of the bean */
    public static final String BEAN_STATUS = "BeanStatus";

    /** Property for the status of the bean structure (Bean with all it's children) */
    public static final String BEAN_STRUCTURE_STATUS = "BeanStructureStatus";

    /**
     * Returns the bean status
     * 
     * @return The bean status
     */
    Status getStatus();

    /**
     * Returns the beanstructure status
     * 
     * @return The beanstructure status
     */
    Status getStructureStatus();

    /**
     * Returns the bean owning this status object.
     * 
     * @return The bean
     */
    T getOwner();

    /**
     * Returns the status of the property with the given name
     * 
     * @param property The name of the property
     * @return The status of the property
     */
    Status getStatus(final String property);

    /**
     * Sets the status of the given property
     * 
     * @param property The property name
     * @param flag The status to set
     */
    void setStatus(final String property, final BeanStatusFlag flag);

    /**
     * Sets the status of the given property
     * 
     * @param property The property name
     * @param flag The status to set
     * @param message The message or null
     */
    void setStatus(final String property, final BeanStatusFlag flag, final String message);

    /**
     * Adds the given listener for property {@link Status} changes.
     * 
     * @param l The listener
     */
    void addStatusChangeListener(PropertyChangeListener l);

    /**
     * Removes the given {@link Status} changes listener.
     * 
     * @param l The listener
     */
    void removeStatusChangeListener(PropertyChangeListener l);

    /**
     * Adds the given listener for property {@link Status} changes of the specified property.
     * 
     * @param property The property to listen
     * @param l The listener
     */
    void addStatusChangeListener(String property, PropertyChangeListener l);

    /**
     * Removes the given property {@link Status} changes listener.
     * 
     * @param property The property to listen
     * @param l The listener
     */
    void removeStatusChangeListener(String property, PropertyChangeListener l);

    /**
     * Sets the given bean status and resets all property status fields!
     * 
     * @param flag The status to set
     * @param message The message to set
     */
    void forceBeanStatus(final BeanStatusFlag flag, final String message);

    /**
     * Resets the initial values to the current values
     */
    void clearInitialValues();

    /**
     * Resets the initial values to the current values and resets the property states (if desired).
     * 
     * @param resetState True if the state of all properties should be set to {@link BeanStatusFlag#UNCHANGED}
     */
    void clearInitialValues(boolean resetState);

    /**
     * Resets the properties of this bean to their initial value.
     * 
     * @throws ResetException If something went wrong
     */
    void resetToInitialValues() throws ResetException;
}
